function createQueryString() {
	var email = $("#email").val();
	var queryString = {
		email : email
	};
	return queryString;
}

function createString() {
	var ident = $("#ident").val();
	var queryString = {
		ident : ident
	};
	return queryString;
}
/**
 * $(function() {
 * 
 * $("#email").focus(function() {
 * jQuery("#emailRequried").attr("class","beforeCheck");
 * jQuery("#email").css("border","1px dotted green");
 * $("#emailRequried").html("请输入你常用的邮箱，方便日后找回密码.");
 * 
 * });
 * 
 * $("#name").focus(function() {
 * jQuery("#emailName").attr("class","beforeCheck");
 * jQuery("#name").css("border","1px dotted green");
 * $("#emailName").html("最好输入汉字，一个汉字为2个字符");
 * 
 * });
 * 
 * $("#password").focus(function() { jQuery("#password").css("border","1px
 * dotted green"); jQuery("#passwordRequried").attr("class",""); });
 * $("#password2").focus(function() {
 * jQuery("#passwordEqual").attr("class","beforeCheck");
 * jQuery("#password2").css("border","1px dotted green");
 * $("#passwordEqual").html("请再次输入密码.");
 * 
 * });
 * 
 * $("#ident").focus(function() {
 * jQuery("#identify").attr("class","beforeCheck");
 * jQuery("#ident").css("border","1px dotted green");
 * $("#identify").html("请输入真实的身份证号码,我们日后会进行实名认证.");
 * 
 * });
 * 
 * });
 */

$(function() {

	$("#email").focus();
	$("#email").blur(function() {
		var reg = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
		if ($.trim($(this).val()) == "") {
			jQuery("#emailRequried").attr("class", "msg error");
			jQuery("#email").css("border", "1px dotted red");
			$("#emailRequried").html("邮箱不能为空");

		} else if (!reg.test($(this).val())) {
			jQuery("#emailRequried").attr("class", "msg error");
			jQuery("#email").css("border", "1px dotted red");
			$("#emailRequried").html("邮箱格式不正确");

		} else {
			jQuery.get(formsScritpUrl+"/user/check_email.do",
					createQueryString(), function(data) {

						if ($.trim(data).length != "") {
							jQuery("#emailRequried").attr("class", "msg error");
							jQuery("#email").css("border", "1px dotted red");
							jQuery("#emailRequried").html(data);
						} else {
							jQuery("#emailRequried").attr("class", "msg ok");
							jQuery("#email").css("border", "1px dotted green");
							jQuery("#emailRequried").html("正确");
							
							if(jQuery("#companyNameValidate").attr("class")=="msg ok"){					
							}else{							
								$("#companyName").focus();
						   }
						}
					});
		}
	});


	$("#companyName").blur(function(){
		var companyName = jQuery(this).val();
		if (!jQuery.trim(companyName)) {
			
			jQuery("#companyNameValidate").attr("class","msg error");
			jQuery("#companyName").css("border","1px dotted red");
			jQuery("#companyNameValidate").html("公司名称不能为空");

		} else {
			jQuery.post(
					formsScritpUrl+"/company/validation!validateCompanyName.do",{companyName:jQuery.trim(companyName)}, function(data) {


								if ($.trim(data)) {
									jQuery("#companyNameValidate").attr("class","msg error");
									jQuery("#companyName").css("border","1px dotted red");
									jQuery("#companyNameValidate").html("对不起!该公司名称已经被使用");
								} else {
									jQuery("#companyNameValidate").attr("class","msg ok");
									jQuery("#companyNameValidate").html("正确");
									
									if(jQuery("#emailName").attr("class")=="msg ok"){					
										
									}else{
									
										$("#name").focus();
								   }
								}
					});
		}
	});

	$("#name").blur(function() {
				if ($.trim($(this).val()) == "") {
					jQuery("#emailName").attr("class", "msg error");
					jQuery("#name").css("border", "1px dotted red");
					$("#emailName").html("用户名不能为空");
				} else {

					jQuery("#emailName").attr("class", "msg ok");
					jQuery("#emailName").html("正确");
					jQuery("#name").css("border", "1px dotted green");
					
					if(jQuery("#passwordRequried").attr("class")=="msg ok"){				
											
					}else{
					
					    $("#password").focus();
				   }
				}
			});

	  $("#password").blur(function() {// 用户密码框失去焦点触发验证事件
	  
	  if ($.trim($(this).val()) == ""){
	  jQuery("#password").css("border","1px dotted red");
	  jQuery("#passwordRequried").attr("class","msg error");
	  $("#passwordRequried").html("密码不能为空"); } 
	  });
	 
	$("#password").pstrength();

	$("#password").blur(function() {
					
			$("#password2").focus();

			})

	$("#password2").blur(function() {
				if ($.trim($(this).val()) == "") {
					jQuery("#passwordEqual").attr("class", "msg error");
					jQuery("#password2").css("border", "1px dotted red");
					$("#passwordEqual").html("密码不能为空");
				} else if ($(this).val() != $("#password").val()) {
					jQuery("#passwordEqual").attr("class", "msg error");
					jQuery("#password2").css("border", "1px dotted red");
					$("#passwordEqual").html("密码必须和上面的一致");
				} else if ($.trim($(this).val()).length < 6) {
					jQuery("#passwordEqual").attr("class", "msg error");
					jQuery("#password2").css("border", "1px dotted red");
					$("#passwordEqual").html("密码长度至少6位");
				} else {
					jQuery("#passwordEqual").attr("class", "msg ok");
					jQuery("#password2").css("border", "1px dotted green");
					jQuery("#passwordEqual").html("正确");
					$("#verifyCode").focus();
				}

			});

	/**$("#ident").blur(function() {
		var reg15 = /^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/;
		var reg18 = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])(\d{3})(\d|x|X)$/;
		if ($.trim($(this).val()) == "") {

			jQuery("#identify").attr("class", "msg error");
			jQuery("#ident").css("border", "1px dotted red");
			$("#identify").html("身份证不能为空");

		} else if ($.trim($(this).val()).length != 15
				&& $.trim($(this).val()).length != 18) {
			jQuery("#identify").attr("class", "msg error");
			jQuery("#ident").css("border", "1px dotted red");
			$("#identify").html("身份证长度必须是15位或者18位");
		} else if (!reg15.test($.trim($(this).val()))
				&& !reg18.test($.trim($(this).val()))) {

			jQuery("#identify").attr("class", "msg error");
			jQuery("#ident").css("border", "1px dotted red");
			$("#identify").html("身份证格式不对");
		}

		else {
			jQuery.post(formsScritpUrl+"/user/check_ident.do", createString(),
					function(data) {

						if ($.trim(data).length != "") {
							jQuery("#identify").attr("class", "msg error");
							jQuery("#ident").css("border", "1px dotted red");
							jQuery("#identify").html(data);
						} else {
							jQuery("#identify").attr("class", "msg ok");
							jQuery("#ident").css("border", "1px dotted green");
							jQuery("#identify").html("正确");

						}
					});

		}

	});*/

		$("#checkAll").click(function() {
						if (this.checked) {
							$("input[name='select']").each(function() {
										this.checked = true;
									});
						} else {
							$("input[name='select']").each(function() {
										this.checked = false;
									});
						}
					});

			var check = function(r) {
				
				return r == "msg error";

			};

			$("#register_submitPage").click(function() {

				var isemailRequried = check($("#emailRequried").attr("class"));
				var isemailName = check($("#emailName").attr("class"));
				var ispasswordRequried = check($("#passwordRequried")
						.attr("class"));
				var ispasswordEqual = check($("#passwordEqual").attr("class"));
				
				var isCompanyNameValidate = check($("#companyNameValidate").attr("class"));
				
			//	var isidentify = check($("#identify").attr("class"));

				var register_check = $("#register_checkbox").attr("checked");

				if (register_check && !isemailRequried &&!isCompanyNameValidate&& !isemailName
						&& !ispasswordRequried && !ispasswordEqual) {

					$("#registerForm").submit();

				} else {

					alert("请根据提示,按步骤正确进行操作");

				}
			});
		});
